package com.flyco.modules.system.service.impl;

import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyco.modules.system.entity.SysRole;
import com.flyco.modules.system.entity.SysUser;
import com.flyco.modules.system.entity.SysUserRole;
import com.flyco.modules.system.mapper.SysUserRoleMapper;
import com.flyco.modules.system.service.ISysRoleService;
import com.flyco.modules.system.service.ISysUserRoleService;
import com.flyco.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * <p>
 * 用户角色表 服务实现类
 * </p>
 *
 * @Author flyco
 * @since 2018-12-21
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {


    @Autowired
    private ISysRoleService roleService;

    @Override
    public List<SysUserRole> getByRoleCode(String roleCode) {
        LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysRole::getRoleCode, roleCode);
        SysRole roleInfo = roleService.getOne(queryWrapper);
        if (roleInfo == null) {
            return null;
        }

        LambdaQueryWrapper<SysUserRole> query = new LambdaQueryWrapper<>();
        query.eq(SysUserRole::getRoleId, roleInfo.getId());
        return list(query);
    }

    @Override
    public List<SysUserRole> getByRoleIds(List<String> roleIds) {

        LambdaQueryWrapper<SysUserRole> query = new LambdaQueryWrapper<>();
        query.in(SysUserRole::getRoleId, roleIds);
        return list(query);
    }
}
